package bairui.international.weixin.portal.miniapp.controller.college.college;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.data.querydsl.QSort;

import com.lianjing.sh.model.uml.model.status.State_UpDown;

import bairui.international.model.domain.jpa.TB_CollegeCategory;
import bairui.international.model.domain.jpa.TB_CollegeCategoryRollImage;
import bairui.international.service.Service_CollegeCategoryRollImage;
import lombok.Getter;

class CategoryOutput {

	private @Getter Long id;
	private @Getter String name;
	private @Getter List<OutputImg> images = new ArrayList<>();

	public CategoryOutput(TB_CollegeCategory bean, Service_CollegeCategoryRollImage service_CollegeCategoryRollImage) {
		this.id = bean.getId();
		this.name = bean.getName();
		if(null != service_CollegeCategoryRollImage){
			this.images = service_CollegeCategoryRollImage
					.list(it -> 
						it.collegeCategory.eq(bean).and(it.state.eq(State_UpDown.Uped)), 
						it -> new QSort(it.orderValue.desc(), it.createTime.desc())
					)
					.getContent()
					.stream()
					.map(it -> new OutputImg(it))
					.collect(Collectors.toList());

		}
	}
	
	private static class OutputImg {
		@Getter private String url;
		@Getter private String imgUrl;
		@Getter private String title;
		
		OutputImg(TB_CollegeCategoryRollImage img){
			this.url = img.getUrl();
			this.imgUrl = C_College_CategoryShow_ShowImg.ShowImg.Operate(img.getId()).getUrl();
			this.title = img.getTitle();
		}
	}
	
}
